import 'package:aio/aio.dart';
import 'package:app/src/http/bean/user.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';

///退货审核；退货信息
class PayFreeReturnBean extends ContractCopyInfo {
  //判断退货审核，是否为退货补片类型。
  bool isReturnsPatch() {
    if ("退货补片" == ReviewTypePosition?.trim()) {
      return true;
    }
    return false;
  }

  //客诉类型
  String? ComplaintType = "";

  //客诉类型id
  String? ComplaintTypeId = "";

  ///判断是否为运输公司的责任
  bool isComplaintTypeId2() {
    if ("2" == ComplaintTypeId?.trim()) {
      return true;
    }
    return false;
  }

  //运输类型
  String? CarType = "";

  //驾驶员
  String? Driver = "";

  //车牌号
  String? CarCode = "";

  //扣除运费
  String? DeductFreight = "";

  //退货方式
  String? PatchingType = "";

  ///是否显示整架入库
  bool isRackgoes() {
    // print(
    //     "==================================================PatchingType:$PatchingType");
    if (PatchingType == "2" || PatchingType == "原单退回") {
      return true;
    }
    return false;
  }

  //退货说明
  String? Intro = "";

  //入库仓库
  List<StorehouseBean>? StorehouseList = null;

  //当前选中的入库仓库，默认选中第一个。fixme 自己加的字段。用于记录选中仓库
  StorehouseBean? Storehouse = null;

  //检验员
  List<UserInfo>? CheckerList = null;

  //当前选中的检验员。fixme 自己加的字段，用于记录选中检验员。
  UserInfo? Checker = null;

  @override
  fromJson(Map<String, dynamic> json) {
    super.fromJson(json);
    // TODO: implement fromJson
    ComplaintType = json['ComplaintType']?.toString() ?? "";
    ComplaintTypeId = json['ComplaintTypeId']?.toString() ?? "";
    CarType = json['CarType']?.toString() ?? "";
    Driver = json['Driver']?.toString() ?? "";
    CarCode = json['CarCode']?.toString() ?? "";
    DeductFreight = json['DeductFreight']?.toString() ?? "";
    PatchingType = json['PatchingType']?.toString() ?? "";
    Intro = json['Intro']?.toString() ?? "";
    StorehouseList = setGenericFromJson(
        json, "StorehouseList", <StorehouseBean>[], StorehouseBean());
    CheckerList =
        setGenericFromJson(json, "CheckerList", <UserInfo>[], UserInfo());
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeReturnBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = super.toJson();
    //var map = <String, dynamic>{};
    map["ComplaintType"] = ComplaintType;
    map["ComplaintTypeId"] = ComplaintTypeId;
    map["CarType"] = CarType;
    map["Driver"] = Driver;
    map["CarCode"] = CarCode;
    map["DeductFreight"] = DeductFreight;
    map["PatchingType"] = PatchingType;
    map["Intro"] = Intro;
    map["StorehouseList"] = StorehouseList;
    map["CheckerList"] = CheckerList;
    return map;
  }
}

///退货审核；入库仓库
///"StorehouseId": 2,
///"StorehouseName": "（江花）成品仓库"
class StorehouseBean extends RollerBean {
  String? StorehouseId = "";
  String? StorehouseName = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    StorehouseId = json['StorehouseId']?.toString() ?? "";
    StorehouseName = json['StorehouseName']?.toString() ?? "";
    key = StorehouseId;
    value = StorehouseName;
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return StorehouseBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["StorehouseId"] = StorehouseId;
    map["StorehouseName"] = StorehouseName;
    return map;
  }
}

//退货审核明细；1级
class PayFreeReturnDetail1 extends BaseBean {
  //退货明细
  List<PayFreeReturnDetail2>? mList = null;

  //合计数量
  String? TNum = "";

  //合计面积
  String? TArea = "";

  //合计金额
  String? TAmount = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    mList = setGenericFromJson(
        json, "List", <PayFreeReturnDetail2>[], PayFreeReturnDetail2());
    TNum = json['TNum']?.toString() ?? "";
    TArea = json['TArea']?.toString() ?? "";
    TAmount = json['TAmount']?.toString() ?? "";
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeReturnDetail1();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["List"] = mList;
    map["TNum"] = TNum;
    map["TArea"] = TArea;
    map["TAmount"] = TAmount;
    return map;
  }
}

//退货审核明细；2级
class PayFreeReturnDetail2 extends BaseBean {
  ///fixme 自己添加的字段。
  bool isOpenAn = false; //是否张开，条目详情
  bool isRackgoes = true; //是否整架入库

  //退货明细
  List<PayFreeReturnDetail3>? Details = null;

  //订单编号
  String? OrderCode = "";

  //订单外部编号
  String? OrderOutCode = "";

  //货品名称
  String? ProductName = "";

  //入库单号
  String? StockInCode = "";

  //箱号
  String? BoxOutCode = "";

  //责任工序
  String? ProcessName = "";

  //责任班组
  String? GroupName = "";

  //责任人
  String? PersonName = "";

  //责任工序
  String? ProcessId = "";

  //责任班组
  String? GroupId = "";

  //责任人
  String? PersonId = "";

  //责任工序列表
  List<MsgProcessBean>? MsgProcess = null;

  ///fixme 责任工序包含责任班组；责任班组包含责任人。

  ///根据当前选中的责任工序，获取责任班组集合
  List<MsgGroupBean>? getMsgGroupWithProcess() {
    List<MsgGroupBean>? msg = null;
    MsgProcess?.forEach((element) {
      if (element.ProcessId == ProcessId) {
        msg = element?.MsgGroup;
      }
    });
    return msg;
  }

  ///根据选中的责任班组；获取责任人集合
  List<UserInfo>? getMsgPersonWithGroup() {
    List<UserInfo>? users = null;
    getMsgGroupWithProcess()?.forEach((element) {
      if (element.GroupId == GroupId) {
        users = element?.MsgPerson;
      }
    });
    return users;
  }

  //退货时间
  String? BackDate = "";

  //数量
  String? DNum = "";

  //面积
  String? DArea = "";

  //金额
  String? DAmount = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    Details = setGenericFromJson(
        json, "Details", <PayFreeReturnDetail3>[], PayFreeReturnDetail3());
    OrderCode = json['OrderCode']?.toString() ?? "";
    OrderOutCode = json['OrderOutCode']?.toString() ?? "";
    ProductName = json['ProductName']?.toString() ?? "";
    StockInCode = json['StockInCode']?.toString() ?? "";
    BoxOutCode = json['BoxOutCode']?.toString() ?? "";
    ProcessName = json['ProcessName']?.toString() ?? "";
    GroupName = json['GroupName']?.toString() ?? "";
    PersonName = json['PersonName']?.toString() ?? "";
    ProcessId = json['ProcessId']?.toString() ?? "";
    GroupId = json['GroupId']?.toString() ?? "";
    PersonId = json['PersonId']?.toString() ?? "";
    MsgProcess = setGenericFromJson(
        json, "MsgProcess", <MsgProcessBean>[], MsgProcessBean());
    BackDate = json['BackDate']?.toString() ?? "";
    DNum = json['DNum']?.toString() ?? "";
    DArea = json['DArea']?.toString() ?? "";
    DAmount = json['DAmount']?.toString() ?? "";
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeReturnDetail2();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["Details"] = Details;
    map["OrderCode"] = OrderCode;
    map["OrderOutCode"] = OrderOutCode;
    map["ProductName"] = ProductName;
    map["StockInCode"] = StockInCode;
    map["BoxOutCode"] = BoxOutCode;
    map["ProcessName"] = ProcessName;
    map["GroupName"] = GroupName;
    map["PersonName"] = PersonName;
    map["ProcessId"] = ProcessId;
    map["GroupId"] = GroupId;
    map["PersonId"] = PersonId;
    map["MsgProcess"] = MsgProcess;
    map["BackDate"] = BackDate;
    map["DNum"] = DNum;
    map["DArea"] = DArea;
    map["DAmount"] = DAmount;
    return map;
  }
}

//退货审核明细；3级
class PayFreeReturnDetail3 extends BaseBean {
  //规格型号
  String? Width_Height = "";

  //安装编号
  String? ItemCode = "";

  //发货数量
  String? Num = "";

  //退货数量
  String? ReturnNum = "";

  //退货分类
  String? HandleMode = "";

  //面积
  String? Area = "";

  //单价
  String? Price = "";

  //金额
  String? Amount = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    Width_Height = json['Width_Height']?.toString() ?? "";
    ItemCode = json['ItemCode']?.toString() ?? "";
    Num = json['Num']?.toString() ?? "";
    ReturnNum = json['ReturnNum']?.toString() ?? "";
    HandleMode = json['HandleMode']?.toString() ?? "";
    Area = json['Area']?.toString() ?? "";
    Price = json['Price']?.toString() ?? "";
    Amount = json['Amount']?.toString() ?? "";
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeReturnDetail3();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["Width_Height"] = Width_Height;
    map["ItemCode"] = ItemCode;
    map["Num"] = Num;
    map["ReturnNum"] = ReturnNum;
    map["HandleMode"] = HandleMode;
    map["Area"] = Area;
    map["Price"] = Price;
    map["Amount"] = Amount;
    return map;
  }
}

//退货审核:责任工序
class MsgProcessBean extends RollerBean {
  //工序Id
  String? ProcessId = "";

  //工序名称
  String? ProcessName = "";

  //责任班组列表
  List<MsgGroupBean>? MsgGroup = null;

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    ProcessId = json['ProcessId']?.toString() ?? "";
    ProcessName = json['ProcessName']?.toString() ?? "";
    MsgGroup =
        setGenericFromJson(json, "MsgGroup", <MsgGroupBean>[], MsgGroupBean());
    key = ProcessId;
    value = ProcessName;
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return MsgProcessBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["ProcessId"] = ProcessId;
    map["ProcessName"] = ProcessName;
    map["MsgGroup"] = MsgGroup;
    return map;
  }
}

//退货审核:责任班组
class MsgGroupBean extends RollerBean {
  //班组Id
  String? GroupId = "";

  //班组名称
  String? GroupName = "";

  //责任人列表
  List<UserInfo>? MsgPerson = null;

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    GroupId = json['GroupId']?.toString() ?? "";
    GroupName = json['GroupName']?.toString() ?? "";
    MsgPerson = setGenericFromJson(json, "MsgPerson", <UserInfo>[], UserInfo());
    key = GroupId;
    value = GroupName;
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return MsgGroupBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["GroupId"] = GroupId;
    map["GroupName"] = GroupName;
    map["MsgPerson"] = MsgPerson;
    return map;
  }
}

//退货审核:退货补片一级列表
class PayFreeGoodReturn extends BaseBean {
  ///是否张开，条目详情
  bool isOpenAn() {
    if (StringUtils.isNotEmpty(mList) && getCPNum() > 0) {
      return true;
    }
    return false;
  }

  //退货补片子数据
  List<PayFreeGoodReturnChild>? mList = null;

  //初始化拆片数据,防止拆片数量，大于可拆片数据。
  void initList() {
    var cp = getCPNum(); //拆片数据
    mList?.forEach((element) {
      if (element.getCPNum() > cp) {
        element.CPNum = cp.toString();
      }
    });
  }

  //任务单号
  String? OrderCode = "";

  //入库单号
  String? StockInCode = "";

  //产品名称
  String? ProductName = null;

  //宽度
  String? ItemWidth = null;

  //高度
  String? ItemHeight = null;

  //安装编号
  String? ItemCode = "";

  //退货数量;(报废数量和拆片数量之和不能大于退货数量)
  String? THNum = null;

  //获取退货数量
  int getTHNum() {
    try {
      var str = THNum?.trim();
      if (StringUtils.isNotEmpty(str)) {
        var d = double.parse(str!);
        return d.toInt();
      }
    } catch (e) {}
    return 0;
  }

  //报废数量
  String? WasteNum = "";

  //获取报废数量
  int getWasteNum() {
    try {
      var str = WasteNum?.trim();
      if (StringUtils.isNotEmpty(str)) {
        var d = double.parse(str!);
        return d.toInt();
      }
    } catch (e) {}
    return 0;
  }

  //拆片数量
  String? CPNum = "";

  //获取拆片数量
  int getCPNum() {
    try {
      var str = CPNum?.trim();
      if (StringUtils.isNotEmpty(str)) {
        var d = double.parse(str!);
        return d.toInt();
      }
    } catch (e) {}
    return 0;
  }

  //退库数量(自动)
  //退货数量 - 报废数量-拆片数量
  //THNum-WasteNum-CPNum
  String? BackNum = "";

  //获取退库数量
  String getBackNumStr() {
    try {
      var num =
          double.parse(THNum!) - double.parse(WasteNum!) - double.parse(CPNum!);
      var str = num.toInt().toString();
      BackNum = str;
      return str;
    } catch (e) {}
    return "0";
  }

  //操作班组
  List<GroupInfoBean>? GroupList = null;

  //自己定义的，当前选中的操作班组
  String? GroupId = "";
  String? GroupName = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    mList = setGenericFromJson(
        json, "List", <PayFreeGoodReturnChild>[], PayFreeGoodReturnChild());
    OrderCode = json['OrderCode']?.toString() ?? "";
    StockInCode = json['StockInCode']?.toString() ?? "";
    ProductName = json['ProductName']?.toString() ?? "";
    ItemWidth = json['ItemWidth']?.toString() ?? "";
    ItemHeight = json['ItemHeight']?.toString() ?? "";
    ItemCode = json['ItemCode']?.toString() ?? "";
    THNum = json['THNum']?.toString() ?? "0";
    WasteNum = json['WasteNum']?.toString() ?? "0";
    CPNum = json['CPNum']?.toString() ?? "0";
    BackNum = json['BackNum']?.toString() ?? "0";
    GroupList = setGenericFromJson(
        json, "GroupList", <GroupInfoBean>[], GroupInfoBean());
    GroupId = json['GroupId']?.toString() ?? "";
    GroupName = json['GroupName']?.toString() ?? "";
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeGoodReturn();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["List"] = mList;
    map["OrderCode"] = OrderCode;
    map["StockInCode"] = StockInCode;
    map["ProductName"] = ProductName;
    map["ItemWidth"] = ItemWidth;
    map["ItemHeight"] = ItemHeight;
    map["ItemCode"] = ItemCode;
    map["THNum"] = THNum;
    map["WasteNum"] = WasteNum;
    map["CPNum"] = CPNum;
    map["BackNum"] = BackNum;
    map["GroupList"] = GroupList;
    map["GroupId"] = GroupId;
    map["GroupName"] = GroupName;
    return map;
  }
}

//退货审核:退货补片二级列表(补片拆分)
class PayFreeGoodReturnChild extends BaseBean {
  //架卡编号
  String? LevelShelfId = "";

  //拆片产品
  String? ProductName = "";

  //条目
  String? OrderItem = null;

  //宽度
  String? ItemWidth = null;

  //高度
  String? ItemHeight = null;

  //可拆片数量(这个服务器目前不返回)
  String? CPNum = "0";

  //获取拆片数量
  int getCPNum() {
    try {
      var str = CPNum?.trim();
      if (StringUtils.isNotEmpty(str)) {
        var d = double.parse(str!);
        return d.toInt();
      }
    } catch (e) {}
    return 0;
  }

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    LevelShelfId = json['LevelShelfId']?.toString() ?? "";
    ProductName = json['ProductName']?.toString() ?? "";
    OrderItem = json['OrderItem']?.toString() ?? "";
    ItemWidth = json['ItemWidth']?.toString() ?? "";
    ItemHeight = json['ItemHeight']?.toString() ?? "";
    CPNum = json['CPNum']?.toString() ?? "0";
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeGoodReturnChild();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["LevelShelfId"] = LevelShelfId;
    map["ProductName"] = ProductName;
    map["OrderItem"] = OrderItem;
    map["ItemWidth"] = ItemWidth;
    map["ItemHeight"] = ItemHeight;
    map["CPNum"] = CPNum;
    return map;
  }
}

//退货审核:退货补片，操作班组
class GroupInfoBean extends RollerBean {
  //班组Id
  String? GroupId = "";

  //班组名称
  String? GroupName = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    GroupId = json['GroupId']?.toString() ?? "";
    GroupName = json['GroupName']?.toString() ?? "";
    key = GroupId;
    value = GroupName;
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return GroupInfoBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["GroupId"] = GroupId;
    map["GroupName"] = GroupName;
    return map;
  }
}

//退货审核详情（已审核）
class PayFreeReturnInfo extends BaseBean {
  //订单编号
  String? OrderCode = "";

  //客诉订单外部编号
  String? ReturnOrderoutCode = "";

  //货品名称
  String? ProductName = "";

  //规格型号
  String? Width_Height = "";

  //原数量
  String? Num = "";

  //退货分类
  String? HandleMode = "";

  //退货数量
  String? ReturnNum = "";

  //退货金额
  String? Amount2 = "";

  //面积
  String? SumArea = "";

  //单价
  String? Price = "";

  //发货金额
  String? Amount = "";

  //架卡号
  String? PositionCode = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    OrderCode = json['OrderCode']?.toString() ?? "";
    ReturnOrderoutCode = json['ReturnOrderoutCode']?.toString() ?? "";
    ProductName = json['ProductName']?.toString() ?? "";
    Width_Height = json['Width_Height']?.toString() ?? "";
    Num = json['Num']?.toString() ?? "";
    HandleMode = json['HandleMode']?.toString() ?? "";
    ReturnNum = json['ReturnNum']?.toString() ?? "";
    Amount2 = json['Amount2']?.toString() ?? "";
    SumArea = json['SumArea']?.toString() ?? "";
    Price = json['Price']?.toString() ?? "";
    Amount = json['Amount']?.toString() ?? "";
    PositionCode = json['PositionCode']?.toString() ?? "";
    // json?.forEach((key, value) {
    //   print("key:$key\tvalue:\t$value");
    // });
  }

  @override
  instance() {
    // TODO: implement instance
    return PayFreeReturnInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["OrderCode"] = OrderCode;
    map["ReturnOrderoutCode"] = ReturnOrderoutCode;
    map["ProductName"] = ProductName;
    map["Width_Height"] = Width_Height;
    map["Num"] = Num;
    map["HandleMode"] = HandleMode;
    map["ReturnNum"] = ReturnNum;
    map["Amount2"] = Amount2;
    map["SumArea"] = SumArea;
    map["Price"] = Price;
    map["Amount"] = Amount;
    map["PositionCode"] = PositionCode;
    return map;
  }
}
